package com.zhzh.sc.demo.redis;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.util.ArrayList;
import java.util.List;

public class TestBloomFilter {

    private static int size = 1000000;
    /**
     * size:预计要插入多少数据
     * fpp: 容错率
     * bloomFilter: 位数组
     * list: 创建的是Object数组
     */
    private static BloomFilter<Integer> bloomFilter = BloomFilter.create(Funnels.integerFunnel(), size, 0.01);

    public static void main(String[] args) {
        for (int i = 1; i < size; i++) {
            bloomFilter.put(i);
        }
        List<Integer> list = new ArrayList<>();
        for (int i = size + 10000; i < size + 20000; i++) {
            if (bloomFilter.mightContain(i)) {
                list.add(i);
            }
        }
        System.out.println("误判数量：" + list.size());
    }
}
